﻿using System;
using System.Diagnostics.CodeAnalysis;

namespace Devonline.Core
{
    /// <summary>
    /// 静态使用的帮助类方法
    /// </summary>
    public static class Helper
    {
        /// <summary>
        /// 适合判断方法的可空参数不应为空的方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="arg"></param>
        public static void ThrowWhenNull([NotNull] object value, string arg = "") => _ = value ?? throw new ArgumentNullException($"{arg} can't be null");

        /// <summary>
        /// 适合判断方法的参数不应为类型的默认值的方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="arg"></param>
        public static void ThrowWhenDefault([NotNull] object value, string arg = "") => _ = value.Equals(default) ? throw new ArgumentNullException($"{arg} can't be null") : value;

        /// <summary>
        /// 适合判断方法的参数既不可为空也不应为类型的默认值的方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="arg"></param>
        public static void ThrowWhenNullOrDefault([NotNull] object value, string arg = "")
        {
            ThrowWhenNull(value, arg);
            ThrowWhenDefault(value, arg);
        }
    }
}